package com.example.sx_06.suxuantv;
import com.blankj.utilcode.util.EncryptUtils;
import org.jetbrains.annotations.NotNull;
import java.net.URLEncoder;

/**
 * ......................我佛慈悲....................
 * ......................_oo0oo_.....................
 * .....................o8888888o....................
 * .....................88" . "88....................
 * .....................(| -_- |)....................
 * .....................0\  =  /0....................
 * ...................___/`---'\___..................
 * ..................' \\|     |// '.................
 * ................./ \\|||  :  |||// \..............
 * .............../ _||||| -卍-|||||- \..............
 * ..............|   | \\\  -  /// |   |.............
 * ..............| \_|  ''\---/''  |_/ |.............
 * ..............\  .-\__  '-'  ___/-. /.............
 * ............___'. .'  /--.--\  `. .'___...........
 * .........."" '<  `.___\_<|>_/___.' >' ""..........
 * ........| | :  `- \`.;`\ _ /`;.`/ - ` : | |.......
 * ........\  \ `_.   \_ __\ /__ _/   .-` /  /.......
 * ....=====`-.____`.___ \_____/___.-`___.-'=====....
 * ......................`=---='.....................
 * ..................佛祖开光 ,永无BUG................
 *
 * @author Created by 李站旗 on 2017/12/7 0007 14:41 .
 * QQ:1032992210
 * E-mail:lizhanqihd@163.com
 * @Description: 统一的网络接口地址
 * 这里域名涉及系统如下:
 * 1.ERP
 * 2.OA(目前沈阳)
 * 3.MC
 * 冲突或者问题:
 * 4.通讯(目前暂时未知归属mc or oa)
 * 5. 登录(erp or mc )
 */

public class Contact {
    /**
     * 获取企业的域名地址的加密校验通讯秘钥
     */
    public final static String CONTACT_KEY = "cf155b8b6d34b1f4e70da28b681ea3f2";
    public final static int PAGE_SIZE = 10;
    /**
     * 获取客户的服务器地址
     */
    public static final String COMPANY_DOMAIN = "http://auth.suxuantech.cn/home/mobile/getProductUrl";
    public static final String OA_PORT = "__OA__";
    public static final String ERP_PORT = "__EPR__";
    public static final String MC_PORT = "__MC__";
    public static final String MY_PORT = "__MY__";
    public static final String CRM_PORT = "__CRM__";
    /**
     * ERP地址
     */
    public static String ERP = "";
    /**
     * OA地址
     */
    public static String OA = "";
    /**
     * MC地址
     */
    public static String MC = "";
    /**
     * CRM地址
     */
    public static String CRM = "";

    /**
     * CRM地址
     */
    public static String My_Server = "http://sx.lizhanqi.top";
    /**
     * Erp 无用的校验
     */
    public static String TOKEN = "^******^";

    private Contact() {        /* cannot be instantiated */
        throw new UnsupportedOperationException("cannot be instantiated");
    }

    /**
     * 重置域名
     */
    public static void reSetCompanyDomain() {
        OA = MC = CRM = ERP = "";
    }


    public static boolean inArray(String[] list, String str) {
        for (String s : list) {
            if (s.equals(str) || s == str) {
                return true;
            }
        }
        return false;
    }

    /**
     * @param template
     * @param replace
     * @return
     */
    public static String getFullUrl(String template, Object... replace) {
        if (template == null) {
            return "";
        }
        if (replace == null) {
            return replaceTemplate(template);
        }

            /**
             * 把传入的对象全部转换为String,因为如果乱传入对象,模板替换的时候出现异常
             */
            for (int i = 0; i < replace.length; i++) {
                replace[i] = replace[i].toString();
            }
            //打印下日志(在这里打印的原因在于这里没进行URL编码)

        /**
         * 1.把所有参数类型转为String,
         * 2.并且编码
         */
        for (int i = 0; i < replace.length; i++) {
            replace[i] = URLEncoder.encode(replace[i].toString());
        }
        return replaceTemplate(template, replace);
    }

    /**
     * 实际进行url模板替换的方法,这里不对外提供使用
     *
     * @param template
     * @param replace
     * @return
     */
    private static String replaceTemplate(String template, @NotNull Object... replace) {
        if (template == null) {
            return "";
        }
        if (replace == null) {
            replace = new Object[0];
        }
        /**   本篇全文的模板规律如下:
         *   /SXWebErpAppStaff开头的为ERP接口
         *   /home 开头的是公司的固定服务器地址`
         *   /api.php开头的是OA接口
         *   /api/开头的是mc的
         *   其他情况则直接返回
         */
        if (template.startsWith(ERP_PORT)) {
            template = template.replaceFirst(ERP_PORT, "");
            return ERP + (String.format(template, replace));
        } else if (template.startsWith("/home")) {
            return COMPANY_DOMAIN + (String.format(template, replace));
        } else if (template.startsWith(OA_PORT)) {

            if (template.startsWith(OA_PORT)) {
                template = template.replaceFirst(OA_PORT, "");
                return OA + String.format(template, replace);
            } else {
                return OA + String.format(template, replace);
            }
        } else if (template.startsWith(MC_PORT)) {
            template = template.replaceFirst(MC_PORT, "");
            return MC + (String.format(template, replace));
        }  else if (template.startsWith(CRM_PORT)) {
            template = template.replaceFirst(CRM_PORT, "");
            return CRM + (String.format(template, replace));
        }
        else if (template.startsWith(MY_PORT)) {
            template = template.replaceFirst(MY_PORT, "");
            return My_Server + (String.format(template, replace));
        } else {
            return template;
        }
    }


    public static class SignateInfo {
        public String signature;
        public int random;
        public long currentTimeMillis;

        public SignateInfo(String signature, int random, long currentTimeMillis) {
            this.signature = signature;
            this.random = random;
            this.currentTimeMillis = currentTimeMillis;
        }
    }

    /**
     * 签名获取
     *
     * @return
     */
    public static SignateInfo getSignate() {
        String signature = "oUWKYeqCEojOvbmsynvWTctJSAVeoMZv";
        int Min = 99999;
        int Max = 999999;
        int random = Min + (int) (Math.random() * ((Max - Min)));
        //java时间戳是13位的毫秒,1000毫秒=1秒,所以需要除以一千 得到的是秒的时间戳也就是10位的
        long currentTimeMillis = System.currentTimeMillis() / 1000;
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(currentTimeMillis);
        stringBuffer.append(random);
        stringBuffer.append(signature);
        signature = EncryptUtils.encryptMD5ToString(stringBuffer.toString()).toLowerCase();
        return new SignateInfo(signature, random, currentTimeMillis);
    }


    /**
     * staffname   password    five=0 ->登录参
     */
    public static String crm_login = CRM_PORT + "/crm/Index/wx_login";

    public static String crm_big_screen = CRM_PORT + "/crm/Bigscreen";
    //聚焦大屏
    public static String crm_ju_jiao = CRM_PORT + "/crm/jujiao";
    //阳光贝贝
    public static String sunbeibei = CRM_PORT + "/crm/sunbeibei/index";






}
